<template>
  <el-form :model="formData" :rules="rules" ref="formCom">
    <el-form-item prop="nickName" label="昵称">
      <el-input v-model="formData.nickName"></el-input>
    </el-form-item>
    <el-form-item prop="userName" label="用户名">
      <el-input v-model="formData.userName"></el-input>
    </el-form-item>
    <el-form-item prop="password" label="密码">
      <el-input v-model="formData.password"></el-input>
    </el-form-item>
    <el-form-item prop="phonenumber" label="手机号">
      <el-input v-model="formData.phonenumber"></el-input>
    </el-form-item>
    <el-form-item prop="email" label="邮箱">
      <el-input v-model="formData.email"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submit"> {{ props.okText }} </el-button>
      <el-button @click="emits('cancel')">{{ props.cancelText }}</el-button>
    </el-form-item>
  </el-form>
</template>

<script setup>
import { reactive, ref } from 'vue'

const props = defineProps({
  okText: {
    type: String,
    default: '提交',
  },
  cancelText: {
    type: String,
    default: '取消',
  },
})
const emits = defineEmits(['submit', 'cancel'])
const formCom = ref()

const formData = reactive({
  nickName: '',
  userName: '',
  password: '',
  phonenumber: '',
  email: '',
})

const rules = reactive({
  nickName: [{ required: true, message: '请输入昵称', trigger: 'blur' }],
  userName: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
  password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
  phonenumber: [],
  email: [],
})

const submit = () => {
  formCom.value.validate((valid) => {
    if (valid) {
      emits('submit', formData)
    }
  })
}
</script>

<style lang="scss" scoped></style>
